package com.niiwoo.civet.trade.service.local.project;

import com.niiwoo.civet.trade.dao.entity.*;
import com.niiwoo.civet.trade.dao.mapper.*;
import com.niiwoo.civet.trade.dto.request.*;
import com.niiwoo.tripod.service.component.SnowflakeIdWorker;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class ProjectLifeLocalService {

    @Autowired
    private SnowflakeIdWorker snowflakeIdWorker;

    @Autowired
    private ProjectLifeCycleMapper projectLifeCycleMapper;

    /**
     * 记录标的生命周期
     * @param projectLifeDTO
     */
    public void recordProjectLife(ProjectLifeDTO projectLifeDTO) {
        ProjectLifeCycle projectLifeCycle = new ProjectLifeCycle();
        projectLifeCycle.setId(snowflakeIdWorker.nextId());
        projectLifeCycle.setCreateTime(projectLifeDTO.getCurrentTime());
        projectLifeCycle.setDesc(projectLifeDTO.getDesc());
        if(projectLifeDTO.getUserId()!=null){
            projectLifeCycle.setManagerId(String.valueOf(projectLifeDTO.getUserId()));
        }
        projectLifeCycle.setType(projectLifeDTO.getType());
        projectLifeCycle.setProjectId(projectLifeDTO.getProjectId());

        projectLifeCycleMapper.insertSelective(projectLifeCycle);
    }

}
